package com.school.service.Impl;

import com.school.common.ServiceResultEnum;
import com.school.entity.Coupon;
import com.school.mapper.CouponMapper;
import com.school.service.CouponService;
import com.school.util.PageQueryUtil;
import com.school.util.PageResult;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import java.util.List;

/**
 * ClassName: CouponServiceImpl
 * Package: com.school.service.impl
 * Description:
 *
 * @Author laohe
 * @Create 2025-07-16 9:17
 * @Version 1.0
 */
@Service
public class CouponServiceImpl implements CouponService {

    @Resource
    private CouponMapper couponMapper;

    @Override
    public PageResult getCouponPage(PageQueryUtil pageQueryUtil) {
        List<Coupon> list = couponMapper.findCouponList(pageQueryUtil);
        int totalCount = couponMapper.getTotalCouponCount(pageQueryUtil);
        return new PageResult(list, totalCount, pageQueryUtil.getLimit(), pageQueryUtil.getPage());
    }

    @Override
    public String saveCoupon(Coupon coupon) {
        if (couponMapper.insertSelective(coupon) > 0) {
            return ServiceResultEnum.SUCCESS.getResult();
        }
        return ServiceResultEnum.DB_ERROR.getResult();
    }
}
